#在原有类的基础上添加方法
class String
    def count_words
        ary=self.split(/\s/)
        return ary.size
    end
end
str1="llp is ztz"
p str1.count_words

#类的继承
class Ringarray<Array #子类<父类
    def [](i)
        idx=i%size
        super(idx) #调用父类同名方法
    end
end
wday=Ringarray["日","一","二","三","四","五","六"]
print wday[1],wday[-2],wday[7],wday[12],"\n"

#方法的别名
class C1
    def hello
        "hello"
    end
    def greet
        "greet"
    end
end
class C2<C1
    undef greet # undef删除父类方法
    alias hello_c1 hello # alias重命名父类方法
    def hello
        "#{hello_c1},again"
    end
end

#单例类
str1="张天泽"
class<<str1
    def hello #单例方法
        "#{self}牛逼"
    end
end
p str1.hello